package com.juyu.miliao.scheduler.dao.mysql;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.juyu.miliao.scheduler.domin.VipPay;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.juyu.miliao.scheduler.domin.UserVip;

@Repository
public class UserVipDao {
	@Autowired
	private SqlSession sqlSession;
	
	public List<UserVip> getUserVipListByStatus(){
		return sqlSession.selectList("getUserVipListByStatus");
	}
	
	public int updateUserVipDate(int userVipId){
		return sqlSession.update("updateUserVipDate", userVipId);
	}
	
	public int updateUserVipStatusByUserVipId(int userVipId){
		return sqlSession.update("updateUserVipStatusByUserVipId", userVipId);
	}

	//马甲包需求
    public List<VipPay> getVipPayListByStatusByUserId(long buyUserId) {
        Map<String, Object> map = new HashMap<>(5);
        map.put("buyUserId", buyUserId);
        return sqlSession.selectList("getVipPayListByStatusByUserId", map);
    }

    public int updateVipPayDate(int id){
        return sqlSession.update("updateVipPayDate", id);
    }
    public int updateVipPayStatusById(int id){
        return sqlSession.update("updateVipPayStatusById", id);
    }


	public UserVip getUserVipInfoById(int userVipId) {
		return sqlSession.selectOne("getUserVipInfoById",userVipId);
	}

	/**
	 * 查询uservip
	 * @param status
	 * 			1:有效，2无效
	 * @return
	 */
	public List<UserVip> selectUserVipInfoByStatus(int status) {
		return sqlSession.selectList("selectUserVipInfoByStatus",status);
	}

    public void updateUserVipExpireTime(int userVipId, LocalDateTime expireTime) {
		Map<String,Object> params = new HashMap<>(2);
		params.put("userVipId",userVipId);
		params.put("expireTime",expireTime);
		sqlSession.update("updateUserVipExpireTime",params);
    }

}
